package com.yanqu.road.server.cmd.banquet;

import com.yanqu.road.entity.banquet.UserBanquetRecord;
import com.yanqu.road.entity.enums.eBanquetType;
import com.yanqu.road.pb.banquet.BanquetProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.banquet.BanquetModule;
import com.yanqu.road.server.manger.banquet.BanquetMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.pb.BanquetPb;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.ArrayList;
import java.util.List;

@Cmd(code = Protocol.S_BANQUET_RECORD_LIST, desc = "请求宴会记录")
public class GetBanquetRecordCmd extends AbstractCommand {

	private int banquetType;
	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		BanquetProto.BanquetGetRecordReq reqMsg = BanquetProto.BanquetGetRecordReq.parseFrom(packet.getBytes());
		banquetType = reqMsg.getBanquetType();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

	}

	@Override
	public void sendData(GamePlayer player) {
		List<UserBanquetRecord> userBanquetRecordList = new ArrayList<>();
		if(banquetType == eBanquetType.ServerNormalBanquet.getValue()){
			userBanquetRecordList = player.getModule(BanquetModule.class).userBanquetRecordList(banquetType);
		}else if(banquetType == eBanquetType.ServerFeastBanquet.getValue()){
			userBanquetRecordList = BanquetMgr.getFeastBanquetRecordList(banquetType);
		}else if(banquetType == eBanquetType.CrossBanquet.getValue() || banquetType == eBanquetType.CrossMogulBirthdayBanquet.getValue()){
			BanquetProto.BanquetGetRecordReq.Builder msg = BanquetProto.BanquetGetRecordReq.newBuilder();
			msg.setBanquetType(banquetType);
			YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.C_CROSS_BANQUET_RECORD_LIST, msg);
			GamePlayerMgr.sendPacket(player.getUserId(), pbMsg);
			return;
		}else if(banquetType == eBanquetType.CrossUserBanquet.getValue()){
			userBanquetRecordList = player.getModule(BanquetModule.class).userBanquetRecordList(banquetType);
		}
		BanquetProto.BanquetGetRecordResp.Builder respMsg = BanquetPb.parseBanquetGetRecordResp(userBanquetRecordList);
		respMsg.setRet(ret);
		player.sendPacket(Protocol.U_BANQUET_RECORD_LIST, respMsg);
	}

}
